﻿using System;
using System.Text;
namespace DotNetAgent.Core
{
	public class AgentException : ApplicationException
	{
		// Methods
		public AgentException()
		{
		}

		public AgentException(string Message)
			: base(Message)
		{
		}

		public AgentException(string Message, Exception InnerException)
			: base(Message, InnerException)
		{
		}

		public AgentException(string Operation, string Message)
			: base("(Operation: " + Operation + ") " + Message)
		{
		}

		public AgentException(string Operation, string Message, Exception InnerException)
			: base("(Operation: " + Operation + ") " + Message, InnerException)
		{
		}

		public static string FormatExceptionString(Exception Ex)
		{
			try
			{
				return Ex == null ?	"" :
						Ex.Message + "{" + Ex.StackTrace.Replace(Environment.NewLine, "|") + "}" +
						Environment.NewLine +
						FormatExceptionString(Ex.InnerException);
			}
			catch (Exception _Ex)
			{
				if (Ex == _Ex)
				{
					return "{***error formatting exception***}";
				}
				return FormatExceptionString(_Ex);
			}
		}
	}
}
